<?php
class UserObjModel extends Model {

	public function getUserById($id) {
		$queryString = sprintf("
			SELECT 
				*
			FROM
				`user`
			WHERE
				`user`.`id` = %d;
		", $id 
		);
		$result = $this->_sqlInstance->query($queryString);
		return $result;
	}
	
	public function setLastLogin($id) {
		$queryString = sprintf("
			UPDATE
				`user`
			SET
				`user`.`date_last_login` = NOW()
			WHERE
				`user`.`id` = %d;
		", $id 
		);
		$result = $this->_sqlInstance->query($queryString);
		return $result;
	}

	public function getCommonAccessWebsites($id) {
		$websites = array();
		$queryString = sprintf("
			SELECT
				`user_site_access`.`id_website`
			FROM
				`user_site_access`
			WHERE
				`user_site_access`.`id_user` = %d
		", $id);
		$result = $this->_sqlInstance->query($queryString);
		if($result) {
			foreach ($result as $row) {
				$websites[] = new Website($row->id_website);
			}
			return $websites;
		}
		return array();
	}
}